cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
set(CMAKE_CXX_STANDARD ${MR_CXX_STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED ON)

project (MRCommonPlugins CXX)

file(GLOB_RECURSE SOURCES "*.cpp")
file(GLOB_RECURSE HEADERS "*.h")


file(GLOB UI_JSON "*.ui.json")
file(GLOB ITEMS_JSON "*.items.json")
IF(MR_EMSCRIPTEN)
	file(COPY ${UI_JSON} DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets")
	file(COPY ${ITEMS_JSON} DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets")
	file(COPY "resource" DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets")
ELSE() # MR_EMSCRIPTEN
	file(COPY ${UI_JSON} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
	file(COPY ${ITEMS_JSON} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
	file(COPY "resource" DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
ENDIF() # MR_EMSCRIPTEN

add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS})

IF(MR_EMSCRIPTEN)
	target_link_libraries(${PROJECT_NAME} PRIVATE
		tbb
		MRMesh
		MRViewer
		glad
		glfw
		imgui
		jsoncpp
		spdlog
		)
ELSE() # NOT MR_EMSCRIPTEN
	target_link_libraries(${PROJECT_NAME} PRIVATE
		tbb
		MRMesh
		MRViewer
		clip
		glad
		glfw
		imgui
		jsoncpp
		spdlog
		fmt
		)
ENDIF() # MR_EMSCRIPTEN


install(TARGETS ${PROJECT_NAME}
		EXPORT ${PROJECT_NAME}
		LIBRARY DESTINATION "${MR_MAIN_LIB_DIR}"
		ARCHIVE DESTINATION "${MR_MAIN_LIB_DIR}"
		RUNTIME DESTINATION "${MR_BIN_DIR}")

install(FILES ${HEADERS}
		DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}")

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake
		DESTINATION ${MR_CONFIG_DIR})

install(FILES ${HEADERS} DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}")
install(FILES ${UI_JSON} DESTINATION "${MR_RESOURCES_DIR}")
install(FILES ${ITEMS_JSON} DESTINATION "${MR_RESOURCES_DIR}")

install(EXPORT ${PROJECT_NAME}
		FILE ${PROJECT_NAME}Targets.cmake
		NAMESPACE MeshLib::
		DESTINATION ${MR_CONFIG_DIR})
